import { createRequire } from 'module'
import { defineConfig, type DefaultTheme } from 'vitepress'

const require = createRequire(import.meta.url)
const pkg = require('vitepress/package.json')

export const zh = defineConfig({
  title: '诚现广告机',
  lang: 'zh-Hans',
  description: '商超政企宣传助手',

  themeConfig: {
    nav: nav(),

    sidebar: {
      '/guide/': { base: '/guide/', items: sidebarGuide() },
      '/dev/': { base: '/dev/', items: sidebarDev() },
      '/reference/': { base: '/reference/', items: sidebarReference() }
    },

    // editLink: {
    //   pattern: 'https://github.com/vuejs/vitepress/edit/main/docs/:path',
    //   text: '在 GitHub 上编辑此页面'
    // },

    footer: {
      message: '<a href="https://beian.miit.gov.cn/">皖ICP备13014211号-12</a> | <a href="https://beian.mps.gov.cn/#/query/webSearch">皖公网安备34019202002499号</a>',
      copyright: `版权所有 © 2016-${new Date().getFullYear()} 合肥纬界信息技术有限公司`
    },

    docFooter: {
      prev: '上一页',
      next: '下一页'
    },

    outline: {
      label: '页面导航'
    },

    lastUpdated: {
      text: '最后更新于',
      formatOptions: {
        dateStyle: 'short',
        timeStyle: 'medium'
      }
    },

    langMenuLabel: '多语言',
    returnToTopLabel: '回到顶部',
    sidebarMenuLabel: '菜单',
    darkModeSwitchLabel: '主题',
    lightModeSwitchTitle: '切换到浅色模式',
    darkModeSwitchTitle: '切换到深色模式'
  }
})

function nav(): DefaultTheme.NavItem[] {
  return [
    {
      text: '文档中心',
      link: '/guide/intro',
      activeMatch: '/guide/'
    },
    {
      text: '常见问题',
      link: '/guide/faq',
      activeMatch: '/guide/'
    },
    {
      text: '产品价格',
      link: '/home/price',
    },
    {
      text: '立即下载',
      link: '/home/download',
    },
    {
      text: '联系我们',
      link: '/home/contact',
    },
    {
      text: '开发者专区',
      link: '/dev/intro',
      activeMatch: '/dev/'
    }
    // {
    //   text: pkg.version,
    //   items: [
    //     {
    //       text: '更新日志',
    //       link: 'https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md'
    //     },
    //     {
    //       text: '参与贡献',
    //       link: 'https://github.com/vuejs/vitepress/blob/main/.github/contributing.md'
    //     }
    //   ]
    // }
  ]
}

function sidebarGuide(): DefaultTheme.SidebarItem[] {
  return [
    {
      text: '简介',
      collapsed: false,
      items: [
        { text: '什么是诚现广告机？', link: 'intro' },
        { text: '为什么要选择我们？', link: 'why' },
        { text: '核心概念', link: 'concepts' }
      ]
    },
    {
      text: '快速开始',
      collapsed: false,
      items: [
        { text: '联网投放', link: 'cast_cloud' },
        { text: '本地投放-内网直连', link: 'cast_lan_direct' },
        { text: '本地投放-私有部署', link: 'cast_lan_deploy' },
        { text: 'U盘投放', link: 'cast_ext' },
        { text: '文件夹播放', link: 'cast_dir' }
      ]
    },
    {
      text: '安装',
      collapsed: false,
      items: [
        { text: '安装概述', link: 'install-intro' },
        { text: '显示端', 
          items: 
            [
              { text: 'Android', link: 'install-player-android' },
              { text: 'Windows', link: 'install-player-windows' },
              { text: 'Linux', link: 'install-player-linux' }
            ]
        },
        { text: '管理端', 
          items: 
            [
              { text: 'Web', link: 'install-admin-web' },
              { text: 'Android', link: 'install-admin-android' },
              { text: 'Windows', link: 'install-admin-windows' },
              { text: 'Linux', link: 'install-admin-linux' }
            ]
        }
      ]
    },
    {
      text: '显示端手册',
      collapsed: false,
      items: [
        { text: '显示端概述', link: 'player_brief' },
        { text: '显示端设置', link: 'player_settings' },
        { text: '横竖屏切换', link: 'player_orientation' },
        { text: '同屏联屏播放', link: 'sync_play' },
      ]
    },
    {
      text: '管理端手册',
      collapsed: false,
      items: [
        {
          text: '节目编辑',
          collapsed: false,
          items: [
            { text: '节目概述', link: 'cast_brief' },
            {
              text: '节目创建',
              collapsed: false,
              items: [
                { text: '从零开始创建', link: 'cast_create_from_start' },
                { text: '从模板创建', link: 'cast_create_from_template' },
                { text: '从ID复制', link: 'cast_create_from_id' }
              ]
            },
            { text: '节目参数介绍', link: 'cast_paras' },
            {
              text: '子屏幕编辑',
              collapsed: false,
              items: [
                { text: '子屏幕概述', link: 'child_screen_brief' },
                { text: '子屏幕增删改', link: 'child_screen_edit' },
                { text: '子屏幕参数介绍', link: 'child_screen_paras' }
              ]
            },
            {
              text: '素材编辑',
              collapsed: false,
              items: [
                { text: '素材概述', link: 'media_brief' },
                { text: '素材增删改', link: 'media_edit' },
                {
                  text: '素材类型及参数',
                  collapsed: false,
                  items: [
                    { text: '概述', link: 'media_type_intro' },
                    { text: '图片', link: 'media_type_image' },
                    { text: '视频', link: 'media_type_video' },
                    { text: '音乐', link: 'media_type_audio' },
                    { text: '文字', link: 'media_type_text' },
                    { text: '网页', link: 'media_type_web' },
                    { text: 'PDF文档', link: 'media_type_pdf' },
                    { text: '内置控件', link: 'media_type_widget' },
                    { text: '子节目', link: 'media_type_child_cast' }
                  ]
                }
              ]
            }
          ]
        },
        { text: '交互式节目制作', link: 'interactive' },
        {
          text: '投放关系',
          collapsed: false,
          items: [
            // { text: '自定义主题', link: 'custom-theme' },
            // { text: '扩展默认主题', link: 'extending-default-theme' },
            // { text: '构建时数据加载', link: 'data-loading' },
            // { text: 'SSR 兼容性', link: 'ssr-compat' },
            { text: '投放概述', link: 'relation_brief' },
            { text: '节目投放', link: 'relation_create' },
            { text: '配置播放计划', link: 'relation_config' }
          ]
        },
        {
          text: '设备管理',
          collapsed: false,
          items: [
            { text: '设备概述', link: 'device_brief' },
            { text: '设备授权', link: 'device_auth' }
          ]
        },
      ]
    },
    {
      text: '常见问题FAQ',
      collapsed: false,
      items: [
        { text: '常见问题', link: 'faq' },
        { text: '如何实现开机自启动？', link: 'faq_auto_start' },
        // { text: '扩展默认主题', link: 'extending-default-theme' },
        // { text: '构建时数据加载', link: 'data-loading' },
        // { text: 'SSR 兼容性', link: 'ssr-compat' },
        // { text: '连接 CMS', link: 'cms' }
      ]
    },
    // {
    //   text: '实验性功能',
    //   collapsed: false,
    //   items: [
    //     { text: 'MPA 模式', link: 'mpa-mode' },
    //     { text: 'sitemap 生成', link: 'sitemap-generation' }
    //   ]
    // },
    // { text: '配置和 API 参考', base: '/zh/reference/', link: 'site-config' }
  ]
}

function sidebarDev(): DefaultTheme.SidebarItem[] {
  return [
    {
      text: '简介',
      link:'intro'
    },
    {
      text: 'API接口',
      link:'api'
    },
    {
      text: '中控协议',
      link:'websocket'
    },
    {
      text: '设备属性接口',
      link:'device_attr'
    }
  ]
}

function sidebarReference(): DefaultTheme.SidebarItem[] {
  return [
    {
      text: '参考',
      items: [
        { text: '站点配置', link: 'site-config' },
        { text: 'frontmatter 配置', link: 'frontmatter-config' },
        { text: '运行时 API', link: 'runtime-api' },
        { text: 'CLI', link: 'cli' },
        {
          text: '默认主题',
          base: '/zh/reference/default-theme-',
          items: [
            { text: '概览', link: 'config' },
            { text: '导航栏', link: 'nav' },
            { text: '侧边栏', link: 'sidebar' },
            { text: '主页', link: 'home-page' },
            { text: '页脚', link: 'footer' },
            { text: '布局', link: 'layout' },
            { text: '徽章', link: 'badge' },
            { text: '团队页', link: 'team-page' },
            { text: '上下页链接', link: 'prev-next-links' },
            { text: '编辑链接', link: 'edit-link' },
            { text: '最后更新时间戳', link: 'last-updated' },
            { text: '搜索', link: 'search' },
            { text: 'Carbon Ads', link: 'carbon-ads' }
          ]
        }
      ]
    }
  ]
}

export const search: DefaultTheme.AlgoliaSearchOptions['locales'] = {
  zh: {
    placeholder: '搜索文档',
    translations: {
      button: {
        buttonText: '搜索文档',
        buttonAriaLabel: '搜索文档'
      },
      modal: {
        searchBox: {
          resetButtonTitle: '清除查询条件',
          resetButtonAriaLabel: '清除查询条件',
          cancelButtonText: '取消',
          cancelButtonAriaLabel: '取消'
        },
        startScreen: {
          recentSearchesTitle: '搜索历史',
          noRecentSearchesText: '没有搜索历史',
          saveRecentSearchButtonTitle: '保存至搜索历史',
          removeRecentSearchButtonTitle: '从搜索历史中移除',
          favoriteSearchesTitle: '收藏',
          removeFavoriteSearchButtonTitle: '从收藏中移除'
        },
        errorScreen: {
          titleText: '无法获取结果',
          helpText: '你可能需要检查你的网络连接'
        },
        footer: {
          selectText: '选择',
          navigateText: '切换',
          closeText: '关闭',
          searchByText: '搜索提供者'
        },
        noResultsScreen: {
          noResultsText: '无法找到相关结果',
          suggestedQueryText: '你可以尝试查询',
          reportMissingResultsText: '你认为该查询应该有结果？',
          reportMissingResultsLinkText: '点击反馈'
        }
      }
    }
  }
}
